package com.yzy.fly.entity.role;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yzy.fly.annotation.RoleChildren;
import com.yzy.fly.kernel.model.FlyBasicModel;
import com.yzy.fly.entity.core.FlySql;
import com.yzy.fly.jarPackage.ClassFileAccess;
import com.yzy.fly.type.FileType;
import com.yzy.fly.util.DateUtil;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.List;

@Data
@TableName("fly_mapper")
public class FlyMapper extends FlyBasicModel<Integer,FlyMapper> implements ClassFileAccess {

    @TableId(type = IdType.AUTO)
    private Integer id;

    private String label;
    private String name;

    private Integer version;
    private Integer access;
    private String superName;
    private String packageName;
    private String className;
    private String modelClassName;
    private String type;

    private String descr;

    private String dataSource;
    private String databaseType;
//    @ParentId
    private Integer componentId;
    private Integer systemId;
    @DateTimeFormat(pattern= DateUtil.DateFormatPattern.yyyy_MM_dd_HH_mm_ss)
    @JsonFormat( pattern = DateUtil.DateFormatPattern.yyyy_MM_dd_HH_mm_ss )
    private Date createTime;
    @DateTimeFormat(pattern= DateUtil.DateFormatPattern.yyyy_MM_dd_HH_mm_ss)
    @JsonFormat( pattern = DateUtil.DateFormatPattern.yyyy_MM_dd_HH_mm_ss )
    private Date updateTime;

    @TableField(exist = false)
    @RoleChildren
    private List<FlySql> sqls;

    @Override
    public String getFileName() {
        return getClassName();
    }

    @Override
    public String getFileSuffix() {
        return FileType.CLASS.getValue();
    }

    @Override
    public String getFilePath() {
        return (getPackageName()+ "."+ getClassName()).replace(".","/");
    }

    @Override
    public String getFileFullPath() {
        return getFilePath() + getFileSuffix();
    }

    public String getLabel(){
        if (StringUtils.isBlank(label)) {
            return name;
        }
        return label;
    }

}
